package com.gacu.viewer.client.algo.match;

import com.gacu.viewer.client.algo.AbsAlgorithm;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class MatchCallback implements AsyncCallback<AbsAlgorithm>
{
	MatchAlgoConfigWidget parent;
	DialogBox db;
	CheckBox ch;
	
	public MatchCallback(MatchAlgoConfigWidget parent)
	{
		this.parent = parent;
	}
	
	@Override
	public void onFailure(Throwable caught) {
		// TODO dekoi de plus beau
		Window.alert(caught.getMessage());
	}

	@Override
	public void onSuccess(AbsAlgorithm result) {
		VerticalPanel vp;
		HorizontalPanel hp;
		Image img;
		
		img = parent.imagesBundle.checkButtonIcon().createImage();//Image("Red_X.png");
		//img.addClickHandler(new CancelClickHandler());
		parent.imageContainer.clear();
		parent.imageContainer.add(img);
		
		db = new DialogBox();
		vp = new VerticalPanel();
		
		vp.add(new Label("Result : "));
		
		hp = new HorizontalPanel();
		hp.add(new Label("Strand : "));
		hp.add(new Label(result.getStructsResult()[0].rna.getGACU()));
		vp.add(hp);
		
		hp = new HorizontalPanel();
		hp.add(new Label("Matches : "));
		hp.add(new Label("" + result.getStructsResult()[0].match));
		vp.add(hp);
		
		ch = new CheckBox("Add strand to pool");
		ch.setValue(true);
		
		vp.add(ch);
		
		vp.add(new Button("Close", new CloseHandler()));
		
		vp.setPixelSize(250, 250);
		db.add(vp);
		db.setPixelSize(250, 250);
		
		db.setText("Server answer");
		db.center();
		db.show();						
		// TODO dekoi de plus beau
		//Window.alert("Ca fonctionne !");
		//Window.alert("" + result.getStructsResult()[0].match);
	}
	
	private class CloseHandler implements ClickHandler
	{		
		@Override
		public void onClick(ClickEvent event) {			
			db.hide();
			
			if (ch.getValue() == true)
			{
				
			}
		}		
	}	
}
